import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import dts from "vite-plugin-dts";
import {resolve} from "path";
import fs from "fs";

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        react(),
        dts({
            tsconfigPath: "tsconfig.app.json",
        }),
        {
            name: "copy-package.json",
            closeBundle() {
                const packageJson = resolve(__dirname, "package.json");
                const distPackageJson = resolve(__dirname, "lib/package.json");
                fs.copyFileSync(packageJson, distPackageJson);
            }
        }
    ],
    build: {
        lib: {
            entry: resolve(__dirname, "src/index.ts"),
            formats: ["es"],
            fileName: "components-lib"
        },
        rollupOptions: {
            external: ["react", "react-dom"],
        },
        outDir: "lib/dist",
        copyPublicDir: false,
    },
    resolve: {
        alias: {
            "@lib": resolve(__dirname, "src"),
        },
    },
})
